//引入express模块
const express = require('express');
//引入连接池模块
const pool = require('../pool.js');
//console.log(pool);
//创建路由器对象
const router = express.Router();

//首页轮播图接口 
router.get('/carousel',(req,res) => {
   //获取id参数
  //  let id = req.query.id
   let sql = "select cid,img,href from se_index_carousel"
   pool.query(sql,(error,results) => {
     if(error) throw error;
   //返回数据到客户端
	 res.send({msg:'ok',code:200,data:results});
   }
)})

//获取首页课程类别接口（导航栏） 
router.get('/category', (req,res) => {
  //获取id参数
  // SQL语句以获取文章分类表的数据
  let sql = 'select nid,img,title,href from se_index_nav ';
  // 执行SQL语句
  pool.query(sql,(error, results) => {
    if (error) throw error;
    res.send({msg: 'ok', code: 200, data: results });
  });
});

// 获取首页课程数据的接口
router.get('/', (req,res) => {
  //获取地址栏中的id参数
  // let id = req.query.id;
  let sql = "select cid,title,pic_title,time,hour,pic,price,href,limitNumber,orderNumber,teacher from se_index_course";
  // 执行SQL查询
  pool.query(sql, (error, results) => {
    if (error) throw error;
    // 返回数据到客户端
    res.send({ msg: 'ok', code: 200, data: results});
  });
});
// 
router.get('/siliu', (req,res) => {
  //获取地址栏中的id参数
  // let id = req.query.id;
  let sql = "select cid,title,pic_title,time,hour,pic,price,href,limitNumber,orderNumber,teacher from se_index_course";
  // 执行SQL查询
  pool.query(sql, (error, results) => {
    if (error) throw error;
    // 返回数据到客户端
    res.send({ msg: 'ok', code: 200, data: results});
  });
});

//导出路由器对象
module.exports = router;